#include <opencv2/opencv.hpp>
#include "RMVideoCapture.h"
#include "Settings.h"
#include "ImageConsProd.h"
#include "iostream"
#include <thread>
using namespace cv;
using namespace std;


int adjustExposure(){
    RMVideoCapture cap("/dev/video1", 3);
    cap.setVideoFormat(1280, 720, 1);
    int exp_t = 5;
    cap.setExposureTime(0, exp_t);//settings->exposure_time);
    cap.startStream();
    cap.info();
    while(1){
        Mat src;
        cap >> src;
        imshow("src", src);
        char key = waitKey(20);
        if (key == 'w'){
            exp_t += 1;
            cap.setExposureTime(0, exp_t);//settings->exposure_time);
            cout << "current exp t:\t" << exp_t << endl;
        }
        else if(key == 's'){
            exp_t -= 1;
            cap.setExposureTime(0, exp_t);
            cout << "current exp t:\t" << exp_t << endl;
        }
    }
}

int main(int argc, char * argv[])
{
//    adjustExposures();
    char *config_file_name = "/home/cz/rm_ws/robomaster_vision/param_config.xml";
    if(argc > 1)
        config_file_name = argv[1];
    Settings setting(config_file_name);
    OtherParam other_param;
    int fd2car = 0;
    // start threads
    ImageConsProd image_cons_prod(&setting, &other_param, fd2car);
    std::thread t1(&ImageConsProd::ImageProducer, image_cons_prod); // pass by reference
    std::thread t2(&ImageConsProd::ImageConsumer, image_cons_prod);

    t1.join();
    t2.join();

    waitKey(0);
    return 0;
}
